
const convert = {
    ToUpper(str) {
        var array = this.regularReplace(str);
        // 单词首字母大写
        array[0] = array[0].charAt(0).toUpperCase() + array[0].substring(1);

        for (let i = 1; i < array.length; i++) {
            array[i] = array[i].charAt(0).toUpperCase() + array[i].substring(1);
        }
        return array.join('');

    },
    ToLowwer(str) {
        var array = this.regularReplace(str);
        //首字母小写
        array[0] = array[0].toLowerCase();

        for (let i = 1; i < array.length; i++) {
            array[i] = array[i].charAt(0).toUpperCase() + array[i].substring(1);
        }
        return array.join('');
    },


    regularReplace(str) {
        str = str.replace(/( and | or | the | at | of | was | a  )/igu, ' ');
        str = str.replace(/(\s?ing|\s?ed|\s?ly)$/igu, '');
        str = str.replace(/^(the )/igu, '');
        str = str.replace(',', '').replace('\'', '');
        return str.split(' ')
    }
}

module.exports = convert;